#!/usr/bin/perl
# Version 0.2.1

$testcase = "ip_header";

# 1 = PASS
# 2 = FAIL
# 3 = INCONCLUSIVE
$verdict = 3;

$dumpfile = "$testcase.dump";
$logfile = "$testcase.log";

if ($#ARGV ne 1) {
        print("Usage: $testcase.pl dump_file log_file");
        exit 1;
}

$dumpfile = $ARGV[0];
$logfile = $ARGV[1];

#------------------------------------------------------------------------------

# Open the dumpfile
$success = 1;
open(DUMPFILE, $dumpfile) or $success = 0;

$verdict_1 = 3;
$verdict_2 = 3;

$initial = 1;
if ($success eq 1) {
	while(<DUMPFILE>) {
		if(/proto 89/) {
			if(/tos (\d*)/) {
				if ($1 eq 0) {
					if( $initial eq 1 ) {
						$verdict_1 = 1;
						$initial = 0;
					}
				} else {
					$verdict_1 = 2;
				}
			}	
		}	
	}
	close(DUMPFILE);
}


# finally evaluate results and generate report
if ($verdict_1 eq 1) {
	print("Packets are sent with TOS 0. Test PASSED.\n");
} elsif ($verdict_1 eq 2) {
	print("IP TOS not 0. Test FAILED.\n");
} else {
	print("Cannot determine IP TOS. Test INCONCLUSIVE.\n");
}

if ($verdict_2 eq 1) {
	print("Precedence flag set. Test PASSED.\n");
} elsif ($verdict_2 eq 2) {
	print("Precedence flag not set. Test FAILED.\n");
} else {
	print("Cannot determine the precedence flag. Test INCONCLUSIVE.\n");
}


$verdict = $verdict_1;
if ($verdict_2 ne $verdict) {
	if($verdict_2 eq 2) {
		$verdict = 2;
	} elsif ($verdict_2 eq 3) {
		if($verdict ne 2) {
			$verdict = 3;
		}
	}	
}

#------------------------------------------------------------------------------
print("### VERDICT for $testcase: ");

if ($verdict eq 1) { 
        print("PASS"); 
} elsif ($verdict eq 2) {
        print("FAIL");
} else {
        print("INCONCLUSIVE");
}

print(" ###\n");